PROJECT = stoicheia
VERSION = 0.3
USR_PATH = /usr/local
VAR_PATH = /var/local
INSTALL_OPTS = -o root -g root -v
INSTALL_OPTS_2 = $(INSTALL_OPTS_BIN) -m 644


all:
	cd webgui; make all
	cd jabber; make all

clean:
	cd webgui; make clean
	cd jabber; make clean

run: all
	cd code; lua5.1 -e 'DEVEL=true' main.lua

arch: clean
	mkdir -p archive
	tar c code image svg template Makefile webgui jabber sound stoicheia README LICENSE | gzip > archive/$(PROJECT)_`date '+%Y-%m-%d_%H-%M-%S'`.tgz

release: clean
	tar c code image svg template Makefile webgui jabber sound stoicheia README LICENSE | gzip > $(PROJECT)_$(VERSION).tgz

install: all uninstall
	install -d $(USR_PATH)/bin
	install -d $(USR_PATH)/share
	install -d $(VAR_PATH)/lib
	install $(INSTALL_OPTS) stoicheia $(USR_PATH)/bin
	install $(INSTALL_OPTS) webgui/webgui $(USR_PATH)/bin
	install $(INSTALL_OPTS) -d $(VAR_PATH)/lib/$(PROJECT)
	install $(INSTALL_OPTS) jabber/jabber.so $(VAR_PATH)/lib/$(PROJECT)
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)/code/plugin
	install $(INSTALL_OPTS_2) code/*.lua $(USR_PATH)/share/$(PROJECT)/code
	install $(INSTALL_OPTS_2) code/plugin/*.lua $(USR_PATH)/share/$(PROJECT)/code/plugin
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)/template
	install $(INSTALL_OPTS_2) template/* $(USR_PATH)/share/$(PROJECT)/template
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)/image
	install $(INSTALL_OPTS_2) image/* $(USR_PATH)/share/$(PROJECT)/image
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)/svg
	install $(INSTALL_OPTS_2) svg/* $(USR_PATH)/share/$(PROJECT)/svg
	install $(INSTALL_OPTS) -d $(USR_PATH)/share/$(PROJECT)/sound
	install $(INSTALL_OPTS_2) sound/* $(USR_PATH)/share/$(PROJECT)/sound

uninstall:
	rm -f $(USR_PATH)/bin/stoicheia
	rm -f $(USR_PATH)/bin/webgui
	rm -rf $(VAR_PATH)/lib/$(PROJECT)
	rm -rf $(USR_PATH)/share/$(PROJECT)


